<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>forget</title>
    <link rel="stylesheet" href="./style2.css" >
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
</head>
<body>
<div class="container">
    <div class="welcome">
        <div class="pinkbox">
            <div class="signin">
                <h1>通过密保问题找回密码</h1>
                    <form class="more-padding" autocomplete="off">
                        <input type="text" placeholder="用户名" required="required" id="yonghuming2">
                        <input type="text" placeholder="密保问题：你父母的名字" required="required" id="answer" >
                        <input type="password" placeholder="密码" required="required" id="newword1">
                        <button class="buttom sumbit" type="button">修改</button>
                    </form>
                </div>
            <div class="signup nodisplay">
            <h1>通过邮箱找回密码</h1>
                <form autocomplete="off" class="connect">
                    <input type="text" placeholder="用户名" required="required" id="yonghuming1">
                    <input type="email" placeholder="邮箱" required="required" id="email">
                    <input type="text" placeholder="验证码" required="required" id="yanzhengma">
                    <input type="password" placeholder="新的密码" required="required" id="newword2">
                    <button id="yanzheng" type="button">获取验证码</button>
                    <button class="button submit" id="create" type="button">修改</button>
                </form>
            </div>
        </div>
        <div class="leftbox">
            <h2 class="title"><span>DESIGNED</span>by<br>YUNTENG</h2>
            <img class="flower smaller" src="1.png" /><br>
            <p class="account">想通过密保问题修改密码?</p>
            <button class="button" id="signin">切换</button>
        </div>
        <div class="rightbox">
            <h2 class="title"><span>DESIGNED</span>by<br>YUNTENG</h2>
            <img class="flower" src="1.png" /><br>
            <p class="account">想通过邮箱修改密码?</p>
            <button class="button" id="signup">切换</button>
        </div>
    </div>
</div>   
<script>
    //var url = decodeURI(window.location.href).split('=');
    //alert(url[1]);
    $('#signup').click(function() {
    $('.pinkbox').css('transform', 'translateX(80%)');
    $('.signin').addClass('nodisplay');
    $('.signup').removeClass('nodisplay');
    });
    $('#signin').click(function() {
    $('.pinkbox').css('transform', 'translateX(0%)');
    $('.signup').addClass('nodisplay');
    $('.signin').removeClass('nodisplay');
    });
    const btns = document.querySelectorAll('button')
    var childStr = document.getElementById("answer").value
    var childStr = document.getElementById("newword1").value
    var childStr = document.getElementById("email").value
    var childStr = document.getElementById("newword2").value
    var childStr = document.getElementById("yanzhengma").value
    var childStr = document.getElementById("yonghuming1").value
    var childStr = document.getElementById("yonghuming2").value
    var cd;
    //问题修改
    btns[0].onclick = function(){
        axios.post(
        'http://yuntenglibrary.natapp1.cc/resetPassword/Encrypted',
        {
            encrypted:answer.value,
            userName:yonghuming2.value,
            newPassword:newword1.value
        }).then(response =>{
            console.log(response)
            alert(response.data.code)
            alert(response.data.status)
            if (response.data.code = 1) {
            //用户丹姐
            window.location.href = "forget.html?uname=" ;
          }
        })
    }
    //验证码 
    btns[1].onclick = function(){
        alert(1)
    axios.post(
        'http://yuntenglibrary.natapp1.cc/resetPassword/Email',
        {
            emailBox:email.value,
            userName:yonghuming1.value
        }).then(response =>{
            console.log(response)
            alert(response.data.cd)
            alert(response.data.status)
            cd = response.data.cd
        })
    }  
    //邮箱修改
    btns[2].onclick = function(){
        if(cd !=null){
            if (yanzhengma.value == cd) {
                alert("验证码正确")
            }
            else{
                alert("验证码错误")
            }
            axios.post(
            'http://yuntenglibrary.natapp1.cc/resetPassword/setting',
            {
                userName:yonghuming1.value,
                newPassword:newword2.value,
            }).then(response =>{
            console.log(response)
            if (response.data.code = 1) {
            //用户丹姐
            window.location.href = "forget.html?uname=";
          }
        })
    }
    }
</script>
</body>
</html>